//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.ddd.mill.infrastructure.utils;

import com.ddd.mill.infrastructure.exception.BizException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.temporal.ChronoField;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;
import java.util.*;

public class DateTimeUtils {
    public static final DateTimeFormatter DATETIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    public static final DateTimeFormatter MONTH_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM");
    public static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
    public static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("HH:mm:ss");
    public static final DateTimeFormatter DATE_S_FORMATTER = DateTimeFormatter.ofPattern("yyyy/MM/dd");
    public static final DateTimeFormatter formatter;
    private static final Logger logger;
    public static final String FULL_HOUR_TIME = " 23:59:59";
    public static final String YYYY_MM_DD = "yyyy-MM-dd";
    public static final String S_YYYY_MM_DD = "yyyy/MM/dd";
    public static final String CN_YYYY_MM_DD = "YYYY年M月d日";
    public static final String YYYYMMDD = "yyyyMMdd";
    public static final String YYYYMMDDHHMM = "yyyyMMddHHmm";
    public static final String YYMMDD = "yyMMdd";
    public static final String HHMM = "HH:MM";
    public static final String YYYYMMDDHH = "yyyyMMddHH";
    public static final String YYMMDDHHMM = "yyMMddHHmm";
    public static final String YYYY_MM_DD_HH_MM = "yyyy-MM-dd HH:mm";
    public static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
    public static final String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
    public static final String YYMMDDHHMMSS = "yyMMddHHmmss";
    public static final String YYYYMMDDHHMMSSSS = "yyyyMMddHHmmssSS";
    public static final String YYMMDDHHMMSSSSS = "yyMMddHHmmssSSS";
    public static final int WEEK_PREFIX_ZHOU = 0;
    public static final int WEEK_PREFIX_XINGQI = 1;
    public static final boolean WEEK_START_SUN = true;
    public static final boolean WEEK_START_MON = false;
    public static final String Y_M = "yyyy-MM";
    public static final String YM = "yyyyMM";
    public static final String D = "dd";
    public static final String Y_M_D_HH = "yyyy-MM-dd HH";
    public static final String M_D_H_MM = "MM-dd HH:mm";
    public static final String MD = "MMdd";
    public static final String HH_MM_CH = "HH点mm分";
    public static final long DAY = 86400000L;
    public static final long HOUR = 3600000L;
    public static final long MINUTE = 60000L;
    public static final long SECOND = 1000L;
    public static final long TIME_ZONE_OFFSET_MILLIS;
    private static final Map<String, ThreadLocal<SimpleDateFormat>> pool;
    private static final Object lock;

    public DateTimeUtils() {
    }

    public static LocalDate parseLocalDate(String dateStr) {
        return LocalDate.parse(dateStr, DATE_FORMATTER);
    }

    public static LocalDateTime parseLocalDateTime(String dateTimeStr) {
        return LocalDateTime.parse(dateTimeStr, DATETIME_FORMATTER);
    }

    public static LocalDateTime parseLocalDateTimeBy(String dateTimeStr) {
        return LocalDate.parse(dateTimeStr, DATE_FORMATTER).atStartOfDay();
    }

    public static LocalTime parseLocalTime(String timeStr) {
        return LocalTime.parse(timeStr, TIME_FORMATTER);
    }

    public static String formatLocalDate(LocalDate date) {
        return date.format(DATE_FORMATTER);
    }

    public static String formatLocalDateTime(LocalDateTime datetime) {
        return datetime.format(DATETIME_FORMATTER);
    }

    public static String formatLocalDateTime2(LocalDateTime datetime) {
        return datetime.format(DATE_FORMATTER);
    }

    public static String formatLocalDateSTime(LocalDateTime datetime) {
        return datetime.format(DATE_S_FORMATTER);
    }

    public static String formatLocalTime(LocalTime time) {
        return time.format(TIME_FORMATTER);
    }

    public static long getTimestampOfDateTime(LocalDateTime localDateTime) {
        if (localDateTime == null) {
            return 0L;
        } else {
            ZoneId zone = ZoneId.systemDefault();
            Instant instant = localDateTime.atZone(zone).toInstant();
            return instant.toEpochMilli();
        }
    }

    public static int periodDays(LocalDate startDateInclusive, LocalDate endDateExclusive) {
        return Period.between(startDateInclusive, endDateExclusive).getDays();
    }

    public static long durationHours(Temporal startInclusive, Temporal endExclusive) {
        return Duration.between(startInclusive, endExclusive).toHours();
    }

    public static long durationMinutes(Temporal startInclusive, Temporal endExclusive) {
        return Duration.between(startInclusive, endExclusive).toMinutes();
    }

    public static long durationMillis(Temporal startInclusive, Temporal endExclusive) {
        return Duration.between(startInclusive, endExclusive).toMillis();
    }

    public static LocalDate getCurrentLocalDate() {
        return LocalDate.now();
    }

    public static LocalTime getCurrentLocalTime() {
        return LocalTime.now();
    }

    public static LocalDateTime get() {
        return LocalDateTime.now();
    }

    public static int getYear() {
        return get().getYear();
    }

    public static LocalDateTime withYear(int year) {
        return get().withYear(year);
    }

    public static int getMonth() {
        return get().getMonthValue();
    }

    public static LocalDateTime firstDayOfThisYear(int year) {
        return withYear(year).with(TemporalAdjusters.firstDayOfYear()).with(LocalTime.MIN);
    }

    public static String getFirstDayOfThisYear(int year) {
        LocalDateTime firstDayOfThisYear = firstDayOfThisYear(year);
        return DATETIME_FORMATTER.format(firstDayOfThisYear);
    }

    public static LocalDateTime lastDayOfThisYear(int year) {
        return withYear(year).with(TemporalAdjusters.lastDayOfYear()).with(LocalTime.MAX);
    }

    public static String getLastDayOfThisYear(int year) {
        LocalDateTime lastDayOfThisYear = lastDayOfThisYear(year);
        return DATETIME_FORMATTER.format(lastDayOfThisYear);
    }

    public static String getFirstDayOfThisMonth() {
        LocalDateTime firstDayOfThisYear = get().with(TemporalAdjusters.firstDayOfMonth());
        return DATETIME_FORMATTER.format(firstDayOfThisYear);
    }

    public static String getLastDayOfThisMonth() {
        LocalDateTime firstDayOfThisYear = get().with(TemporalAdjusters.lastDayOfMonth());
        return DATETIME_FORMATTER.format(firstDayOfThisYear);
    }

    public static LocalDateTime plusDays(int days) {
        return get().plusDays((long)days);
    }

    public static LocalDateTime firstDayOfWeekInYearMonth(int year, int month) {
        return get().withYear(year).withMonth(month).with(TemporalAdjusters.firstInMonth(DayOfWeek.MONDAY));
    }

    public static LocalDateTime todayStart() {
        return LocalDateTime.of(getCurrentLocalDate(), LocalTime.MIN);
    }

    public static LocalDateTime todayEnd() {
        return LocalDateTime.of(getCurrentLocalDate(), LocalTime.MAX);
    }

    public static String getStartDayOfWeekToString() {
        return formatLocalDate(getStartDayOfWeek());
    }

    public static LocalDate getStartDayOfWeek() {
        TemporalAdjuster FIRST_OF_WEEK = TemporalAdjusters.ofDateAdjuster((localDate) -> {
            return localDate.minusDays((long)(localDate.getDayOfWeek().getValue() - DayOfWeek.MONDAY.getValue()));
        });
        return getCurrentLocalDate().with(FIRST_OF_WEEK);
    }

    public static String getEndDayOfWeekToString() {
        return formatLocalDate(getEndDayOfWeek());
    }

    public static LocalDate getEndDayOfWeek() {
        TemporalAdjuster LAST_OF_WEEK = TemporalAdjusters.ofDateAdjuster((localDate) -> {
            return localDate.plusDays((long)(DayOfWeek.SUNDAY.getValue() - localDate.getDayOfWeek().getValue()));
        });
        return getCurrentLocalDate().with(LAST_OF_WEEK);
    }

    public static SimpleDateFormat getDateFormat(String pattern) {
        ThreadLocal<SimpleDateFormat> tl = (ThreadLocal)pool.get(pattern);
        if (tl == null) {
            synchronized(lock) {
                tl = (ThreadLocal)pool.get(pattern);
                if (tl == null) {
                    tl = new ThreadLocal<SimpleDateFormat>() {
                        @Override
                        protected synchronized SimpleDateFormat initialValue() {
                            return new SimpleDateFormat(pattern);
                        }
                    };
                    pool.put(pattern, tl);
                }
            }
        }

        return (SimpleDateFormat)tl.get();
    }

    public static long getNowTimeLong() {
        return System.currentTimeMillis();
    }

    public static Date getNowDate() {
        Date date = new Date();
        String dateString = getDateFormat("yyyy-MM-dd").format(date);

        try {
            date = getDateFormat("yyyy-MM-dd").parse(dateString);
        } catch (ParseException var3) {
            logger.error("ParseException", var3);
        }

        return date;
    }

    public static long getNowDateLong() {
        return getNowDate().getTime();
    }

    public static long getDateLong(String dateString) {
        Date date;
        try {
            date = getDateFormat("yyyy-MM-dd").parse(dateString);
        } catch (ParseException var3) {
            date = new Date();
            logger.error("ParseException", var3);
        }

        return date.getTime();
    }

    public static long getTimeLong(String timeString) {
        Date date = null;

        try {
            date = getDateFormat("yyyy-MM-dd HH:mm:ss").parse(timeString);
        } catch (ParseException var3) {
            date = new Date();
            logger.error("ParseException", var3);
        }

        return date.getTime();
    }

    public static String getNowDateStringNOLine() {
        return getDateFormat("yyyyMMdd").format(new Date());
    }

    public static String getDateStringLine(Date date) {
        return getDateFormat("yyyy-MM-dd").format(date);
    }

    public static String getDateStringYyyyMMddHHLine(Date date) {
        return getDateFormat("yyyy-MM-dd HH:mm").format(date);
    }

    public static String getDateStringNOLine(Date date) {
        return getDateFormat("yyyyMMdd").format(date);
    }

    public static String getDateStringYyyyMMddHH(Date date) {
        return getDateFormat("yyyyMMddHH").format(date);
    }

    public static String getNowString() {
        return getDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
    }

    public static String getNowStringNOLine() {
        return getDateFormat("yyyyMMddHHmmss").format(new Date());
    }

    public static String getNowStringNOLineMs() {
        return getDateFormat("yyyyMMddHHmmssSS").format(new Date());
    }

    public static String getDateTimeStringNOLine(Date date) {
        return getDateFormat("yyyyMMddHHmmss").format(date);
    }

    public static String getNowDateString() {
        return getDateFormat("yyyy-MM-dd").format(new Date());
    }

    public static String getLongDateString(Date time) {
        return getDateFormat("yyyy-MM-dd HH:mm").format(time);
    }

    public static String getTimeString(Date time) {
        return getDateFormat("yyyy-MM-dd HH:mm:ss").format(time);
    }

    public static String getDateString(Date time) {
        return getDateFormat("yyyy-MM-dd").format(time);
    }

    public static String getDateStringSDate(Date time) {
        return getDateFormat("yyyy-MM-dd").format(time);
    }

    public static String getTomorrowString(String format) {
        Date tomorrow = getDateBefore(new Date(), -1);
        return getDateFormat(format).format(tomorrow);
    }

    public static Date getDateDate(String time) {
        Date d = null;

        try {
            d = getDateFormat("yyyy-MM-dd").parse(time);
        } catch (ParseException var3) {
            logger.error("时间格式转换错误", var3);
        }

        return d;
    }

    public static Date getTimeDate(String time) {
        Date d = null;

        try {
            d = getDateFormat("yyyy-MM-dd HH:mm:ss").parse(time);
        } catch (ParseException var3) {
            logger.error("格式转换错误", var3);
        }

        return d;
    }

    public static Date getTimeDateNoSecond(String time) {
        Date d = null;

        try {
            d = getDateFormat("yyyy-MM-dd HH:mm").parse(time);
        } catch (ParseException var3) {
            logger.error("格式转换错误", var3);
        }

        return d;
    }

    public static Date getLastMonthTime(Date time) {
        return getTimeBefore(time, 1, 2);
    }

    public static Date getDateBefore(Date d, int day) {
        return getTimeBefore(d, day, 5);
    }

    public static String getDateStringBefore(Date d, int day) {
        Date date = getDateBefore(d, day);
        return getDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
    }

    public static List<String> getDateStringBeforeSeven(Date d) {
        List<String> sevenString = new ArrayList();

        for(int i = 1; i <= 7; ++i) {
            Date date = getDateBefore(d, i);
            String format = getDateFormat("yyyy-MM-dd").format(date);
            sevenString.add(format);
        }

        return sevenString;
    }

    public static List<String> getDateStringBeforeFive(Date d) {
        List<String> fiveString = new ArrayList();

        for(int i = 1; i <= 5; ++i) {
            Date date = getDateBefore(d, i);
            String format = getDateFormat("yyyy-MM-dd").format(date);
            fiveString.add(format);
        }

        return fiveString;
    }

    public static String getDateStringBefore(Date d, int day, String format) {
        Date date = getDateBefore(d, day);
        return getDateFormat(format).format(date);
    }

    public static String getDateStringBefore(String dateStr, int day, String format) {
        Date date;
        try {
            date = getDateFormat("yyyy-MM-dd").parse(dateStr);
        } catch (ParseException var5) {
            var5.printStackTrace();
            date = new Date();
        }

        date = getDateBefore(date, day);
        return getDateFormat(format).format(date);
    }

    public static Date parseDateNoLine(String date) {
        Date d = null;

        try {
            d = getDateFormat("yyyyMMddHHmmss").parse(date);
        } catch (ParseException var3) {
            logger.error("格式转换错误", var3);
        }

        return d;
    }

    public static String formatDateLong(long dateLong) {
        Date date = new Date(dateLong);
        return format("yyyy-MM-dd", date);
    }

    public static String formatChinaDate(long milliseconds) {
        return formatChinaDate(new Date(milliseconds));
    }

    public static String formatChinaDate(Date date) {
        return format("YYYY年M月d日", date);
    }

    public static String formatTimeLong(long timeLong) {
        Date date = new Date(timeLong);
        return format("yyyy-MM-dd HH:mm:ss", date);
    }

    public static String formatLong(String pattern, long timeLong) {
        Date date = new Date(timeLong);
        return format(pattern, date);
    }

    public static String formatLong(long timeLong) {
        Date date = new Date(timeLong);
        return format("yyyy-MM-dd", date);
    }

    public static String formatTimeLongNoSecond(long timeLong) {
        Date date = new Date(timeLong);
        return format("yyyy-MM-dd HH:mm", date);
    }

    public static Date getYesterday() {
        return getDateBefore(new Date(), 1);
    }

    public static String getYesterDayString() {
        Date yesterday = getYesterday();
        return getDateString(yesterday);
    }

    public static String getFullDayString(String date) {
        return date + " 23:59:59";
    }

    public static List<Date> findDates(Date beginTime, Date endTime) {
        List<Date> lDate = new ArrayList();
        lDate.add(beginTime);
        Calendar calBegin = Calendar.getInstance();
        calBegin.setTime(beginTime);
        Calendar calEnd = Calendar.getInstance();
        calEnd.setTime(endTime);

        while(endTime.after(calBegin.getTime())) {
            lDate.add(calBegin.getTime());
            calBegin.add(5, 1);
        }

        return lDate;
    }

    public static List<String> findDateStr(Date beginTime, Date endTime) {
        List<String> lDate = new ArrayList();
        Calendar calBegin = Calendar.getInstance();
        calBegin.setTime(beginTime);
        Calendar calEnd = Calendar.getInstance();
        calEnd.setTime(endTime);

        while(endTime.after(calBegin.getTime())) {
            lDate.add(getDateString(calBegin.getTime()));
            calBegin.add(5, 1);
        }

        return lDate;
    }

    public static String getNextWeekDateName() {
        Calendar cal = Calendar.getInstance();
        cal.add(5, 7);
        int year = cal.get(1);
        int month = cal.get(2) + 1;
        int week = cal.get(8);
        return year + "年" + month + "月第" + week + "周";
    }

    public static Date getNextWeekMonday() {
        Calendar cal = Calendar.getInstance();
        int n = 1;
        cal.add(5, n * 7);
        cal.set(7, 2);
        return cal.getTime();
    }

    public static Date getNextWeekSunday() {
        Calendar cal = Calendar.getInstance();
        int n = 2;
        cal.add(5, n * 7);
        cal.set(7, 1);
        return cal.getTime();
    }

    public static String getWeekDay(int i, Integer prefix) {
        String day;
        switch(i) {
            case 1:
                day = "天";
                break;
            case 2:
                day = "一";
                break;
            case 3:
                day = "二";
                break;
            case 4:
                day = "三";
                break;
            case 5:
                day = "四";
                break;
            case 6:
                day = "五";
                break;
            case 7:
                day = "六";
                break;
            default:
                day = "日";
        }

        String prefixStr = prefix != null && prefix != 0 ? "星期" : "周";
        return prefixStr + day;
    }

    public static boolean isPast(String date) {
        long nowDateLong = getNowDateLong();
        long dateLong = getDateLong(date);
        return nowDateLong > dateLong;
    }

    public static boolean isPast(Date date, int day) {
        long nowDateLong = System.currentTimeMillis();
        long dateLong = date.getTime();
        long pastTime = (long)(day * 24 * 60 * 60) * 1000L;
        return nowDateLong > dateLong + pastTime;
    }

    public static Date getDateByMills(Long mills) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(mills);
        return calendar.getTime();
    }

    public static String format(String pattern, Date date) {
        return getDateFormat(pattern).format(date);
    }

    public static Date parse(String pattern, String date) {
        Date time = new Date();

        try {
            time = getDateFormat(pattern).parse(date);
        } catch (ParseException var4) {
            logger.error(var4.getMessage());
            var4.printStackTrace();
        }

        return time;
    }

    public static int daysBetween(Date smdate, Date bdate) {
        return dateBetween(smdate, bdate, 86400000L);
    }

    public static int dateBetween(Date smdate, Date bdate, long timeType) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(smdate);
        long time1 = cal.getTimeInMillis();
        cal.setTime(bdate);
        long time2 = cal.getTimeInMillis();
        long between = (time2 - time1) / timeType;
        return Integer.parseInt(String.valueOf(between));
    }

    public static int timeBetween(Long smtime, Long btime, long timeType) {
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(smtime);
        long time1 = cal.getTimeInMillis();
        cal.setTimeInMillis(btime);
        long time2 = cal.getTimeInMillis();
        long between = (time2 - time1) / timeType;
        return Integer.parseInt(String.valueOf(between));
    }

    public static int daysBetween(String smdate, String bdate) throws ParseException {
        return daysBetween(getDateFormat("yyyy-MM-dd").parse(smdate), getDateFormat("yyyy-MM-dd").parse(bdate));
    }

    public static Date getHourBefore(Date d, int hour) {
        return getTimeBefore(d, hour, 10);
    }

    public static Date getMinuteBefore(Date d, int minute) {
        return getTimeBefore(d, minute, 12);
    }

    public static Date getTimeBefore(Date d, int num, int type) {
        Calendar now = Calendar.getInstance();
        now.setTime(d);
        now.add(type, -1 * num);
        return now.getTime();
    }

    public static String changeTime(int num, long timeType) {
        String res = "";
        int day;
        int hour;
        int minute;
        if (timeType == 1000L) {
            if (num / 60 < 1) {
                res = num + "秒";
            } else {
                int second;
                if (num / 60 / 60 < 1) {
                    minute = num / 60;
                    second = num % 60;
                    res = minute + "分钟" + second + "秒";
                } else if (num / 60 / 60 / 24 < 1) {
                    hour = num / 60 / 60;
                    minute = num % 3600 / 60;
                    second = num % 3600 % 60;
                    res = hour + "小时" + minute + "分钟" + second + "秒";
                } else {
                    day = num / 60 / 60 / 24;
                    hour = num % 86400 / 3600;
                    minute = num % 86400 % 3600 / 60;
                    second = num % 86400 % 3600 % 60;
                    res = day + "天" + hour + "小时" + minute + "分钟" + second + "秒";
                }
            }
        } else if (timeType == 60000L) {
            if (num / 60 < 1) {
                res = num + "分钟";
            } else if (num / 60 / 24 < 1) {
                hour = num / 60;
                minute = num % 60;
                res = hour + "小时" + minute + "分钟";
            } else {
                day = num / 60 / 24;
                hour = num % 1440 / 60;
                minute = num % 1440 % 60;
                res = day + "天" + hour + "小时" + minute + "分钟";
            }
        } else if (timeType == 3600000L) {
            if (num / 24 < 1) {
                res = num + "小时";
            } else {
                day = num / 24;
                hour = num % 24;
                res = day + "天" + hour + "小时";
            }
        }

        return res;
    }

    public static int recursionAlgorithm(int n) {
        if (n <= 0) {
            return 0;
        } else {
            return n <= 2 ? 1 : recursionAlgorithm(n - 2) + recursionAlgorithm(n - 1);
        }
    }

    public static int add(int n) {
        if (n <= 0) {
            return 0;
        } else {
            return n == 1 ? 10 : add(n - 1) + add(n - 1) - add(n - 3) - 1;
        }
    }

    public static Date getFirstDayOfWeek(Date date) {
        Calendar c = new GregorianCalendar();
        c.setFirstDayOfWeek(2);
        c.setTime(date);
        c.set(7, c.getFirstDayOfWeek());
        return c.getTime();
    }

    public static Date getLastDayOfWeek(Date date) {
        Calendar c = new GregorianCalendar();
        c.setFirstDayOfWeek(2);
        c.setTime(date);
        c.set(7, c.getFirstDayOfWeek() + 6);
        return c.getTime();
    }

    public static String getLastDayOfMonth(int year, int month) {
        Calendar cal = Calendar.getInstance();
        cal.set(1, year);
        cal.set(2, month - 1 + 1);
        cal.set(5, 1);
        cal.add(5, -1);
        return formatDateLong(cal.getTimeInMillis());
    }

    public static String getFirstDayOfMonth(int year, int month) {
        Calendar cal = Calendar.getInstance();
        cal.set(1, year);
        cal.set(2, month - 1);
        cal.set(5, 1);
        return formatDateLong(cal.getTimeInMillis());
    }

    public static String[] getFirstLastDayOfMonth(String time) {
        String begin = "";
        String end = "";
        if (StringUtils.isNotEmpty(time)) {
            String[] ym = time.split("-");
            int year = Integer.parseInt(ym[0]);
            int month = Integer.parseInt(ym[1]);
            begin = getFirstDayOfMonth(year, month);
            end = getLastDayOfMonth(year, month);
        }

        return new String[]{begin, end};
    }

    public static long getTimeAfter(long time, int num, int type) {
        Calendar now = Calendar.getInstance();
        now.setTimeInMillis(time);
        now.add(type, num);
        return now.getTimeInMillis();
    }

    public static String getFirstDay(Date date) {
        Calendar c = Calendar.getInstance();
        c.add(2, 0);
        c.setTime(date);
        c.set(5, 1);
        String firstDay = getDateString(c.getTime());
        return firstDay;
    }

    public static String getLastDay(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.set(5, c.getActualMaximum(5));
        String lastDay = getDateString(c.getTime());
        return lastDay;
    }

    public static String getWeekDays(int year, int week, int targetNum) {
        if (week + targetNum > 52) {
            ++year;
            week += targetNum - 52;
        } else if (week + targetNum <= 0) {
            --year;
            week += targetNum + 52;
        } else {
            week += targetNum;
        }

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        cal.setFirstDayOfWeek(1);
        cal.set(1, year);
        cal.set(3, week);
        cal.set(7, cal.getFirstDayOfWeek());
        String beginDate = sdf.format(cal.getTime());
        cal.add(7, 6);
        String endDate = sdf.format(cal.getTime());
        return beginDate + "~" + endDate;
    }

    public static boolean beforeNowDate(Date date) {
        return getNowDate().getTime() > date.getTime();
    }

    public static boolean beforeNowDate(String date) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

        Date time;
        try {
            time = simpleDateFormat.parse(date);
        } catch (ParseException var4) {
            var4.printStackTrace();
            throw new BizException("时间格式化失败");
        }

        return beforeNowDate(time);
    }

    public static boolean beforeNowDateHaveNowDate(Date date) {
        return getNowDate().getTime() >= date.getTime();
    }

    public static boolean beforeNowDateHaveNowDate(String date) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

        Date time;
        try {
            time = simpleDateFormat.parse(date);
        } catch (ParseException var4) {
            var4.printStackTrace();
            throw new BizException("时间格式化失败");
        }

        return beforeNowDateHaveNowDate(time);
    }

    public static String getWeekByDate(Date date, Integer prefix) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int i = c.get(7);
        return getWeekDay(i, prefix);
    }

    public static String getWeekByDate(Date date) {
        return getWeekByDate(date, (Integer)null);
    }

    public static String getWeekByDateLimitFour(Date date, Integer prefix) {
        return getWeekByDateLimit(date, prefix, 4);
    }

    public static String getWeekByDateLimit(Date date, Integer prefix, int maxDateBetween) {
        int i = daysBetween(date, getNowDate());
        i = maxDateBetween == 3 && i == -2 ? -3 : i;
        String desc;
        switch(i) {
            case -2:
                desc = " 后天";
                break;
            case -1:
                desc = " 明天";
                break;
            case 0:
                desc = " 今天";
                break;
            case 1:
                desc = " 昨天";
                break;
            default:
                desc = getWeekByDate(date, prefix);
        }

        return desc;
    }

    public static String getWeekByDateLimitThree(Date date, Integer prefix) {
        return getWeekByDateLimit(date, prefix, 3);
    }

    public static String getWeekByDateLimitThree(Date date) {
        return getWeekByDateLimitThree(date, (Integer)null);
    }

    public static String getMonthWeek(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        Calendar firstDay = Calendar.getInstance();
        firstDay.setTime(date);
        firstDay.set(5, 1);
        boolean firstDayIsSun = firstDay.get(7) == 1;
        StringBuilder builder = (new StringBuilder()).append(calendar.get(1)).append("年").append(calendar.get(2) + 1).append("月第");
        int weekOfMonth = calendar.get(4);
        if (!firstDayIsSun) {
            if (weekOfMonth == 1) {
                firstDay.add(2, -1);
                weekOfMonth = firstDay.getActualMaximum(4);
                firstDayIsSun = firstDay.get(7) == 1;
                if (!firstDayIsSun) {
                    --weekOfMonth;
                }

                builder = (new StringBuilder()).append(firstDay.get(1)).append("年").append(firstDay.get(2) + 1).append("月第");
            } else {
                --weekOfMonth;
            }
        }

        builder.append(weekOfMonth).append("周(");
        calendar.set(7, 1);
        builder.append(calendar.get(2) + 1).append(".").append(calendar.get(5)).append("~");
        calendar.set(7, 7);
        builder.append(calendar.get(2) + 1).append(".").append(calendar.get(5)).append(")");
        return builder.toString();
    }

    public static String getQuarter(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        StringBuilder builder = (new StringBuilder()).append(calendar.get(1)).append("年第");
        int month = calendar.get(2) + 1;
        byte quarter;
        if (month <= 3) {
            quarter = 1;
        } else if (month <= 6) {
            quarter = 2;
        } else if (month <= 9) {
            quarter = 3;
        } else {
            quarter = 4;
        }

        builder.append(quarter).append("季度");
        return builder.toString();
    }

    public static String getWeekByDateLimitFour(Date date) {
        return getWeekByDateLimitFour(date, (Integer)null);
    }

    public static Long getStartTime() {
        Calendar todayStart = Calendar.getInstance();
        todayStart.set(11, 0);
        todayStart.set(12, 0);
        todayStart.set(13, 0);
        todayStart.set(14, 0);
        return todayStart.getTime().getTime();
    }

    public static Long getEndTime() {
        Calendar todayEnd = Calendar.getInstance();
        todayEnd.set(11, 23);
        todayEnd.set(12, 59);
        todayEnd.set(13, 59);
        todayEnd.set(14, 999);
        return todayEnd.getTime().getTime();
    }

    public static Long getStartTime(Date date) {
        Calendar todayStart = Calendar.getInstance();
        todayStart.setTime(date);
        todayStart.set(10, 0);
        todayStart.set(12, 0);
        todayStart.set(13, 0);
        todayStart.set(14, 0);
        return todayStart.getTime().getTime();
    }

    public static Long getEndTime(Date date) {
        Calendar todayEnd = Calendar.getInstance();
        todayEnd.setTime(date);
        todayEnd.set(10, 23);
        todayEnd.set(12, 59);
        todayEnd.set(13, 59);
        todayEnd.set(14, 999);
        return todayEnd.getTime().getTime();
    }

    public static void main(String[] args) {
        LocalDateTime localDateTime = LocalDate.parse("2020-03-01", DATE_FORMATTER).atStartOfDay();
        Long startTime = getStartTime();
        System.out.println(startTime);
        Long endTime = getEndTime();
        System.out.println(endTime);
    }

    static {
        formatter = (new DateTimeFormatterBuilder()).appendPattern("yyyy-MM-dd[['T'HH][:mm][:ss]]").parseDefaulting(ChronoField.HOUR_OF_DAY, 0L).parseDefaulting(ChronoField.MINUTE_OF_HOUR, 0L).parseDefaulting(ChronoField.SECOND_OF_MINUTE, 0L).parseDefaulting(ChronoField.MILLI_OF_SECOND, 0L).toFormatter();
        logger = LoggerFactory.getLogger(DateTimeUtils.class);
        TIME_ZONE_OFFSET_MILLIS = (long)TimeZone.getDefault().getRawOffset();
        pool = new HashMap();
        lock = new Object();
    }
}
